<html>
<head>
<meta NAME="author" CONTENT="Zsolt Mohacsi">
    <script type="text/javascript" src="../../sh_main.js"></script>
    <script type="text/javascript" src="../../sh_javascript.js"></script>
    <script type="text/javascript" src="../../sh_html.js"></script>
    <link REL ="stylesheet" TYPE="text/css" HREF="../../sh_nedit.css" TITLE="Style">
<link REL ="stylesheet" TYPE="text/css" HREF="../../../marvinmanuals.css" TITLE="Style">
<title>MarvinSketch Example - Molecular property calculations with Chemical Terms</title>
</head>

<!--  Important!  -->
<body onUnLoad="document.MSketch=null" onload="sh_highlightDocument();">

<h1>MarvinSketch Example - Molecular property calculations with Chemical Terms</h1>

<p>Select a <a href="../../../help/chemicalterms/ChemicalTerms.html">Chemical Terms</a>
 expression from the list, enter one, or modify the molecule (delete some atoms or bonds, 
 draw new ones), and watch how the calculated field changes. 
 
<p>
<center>
<script LANGUAGE="JavaScript1.1" SRC="../../../marvin.js"></script>
<script LANGUAGE="JavaScript1.1">
<!--
function evaluateChemicalTerms(expression) {
    document.CTForm.Expression.value = expression;
    if(document.MSketch != null) {
        var result = document.MSketch.evaluateChemicalTerms(expression);
        if (document.MSketch.isChemicalTermsExpressionSyntaxError()) {
            document.CTForm.Result.style.color = '#F00';
       	    document.CTForm.Result.value = "Syntax error.";
        } else {
            document.CTForm.Result.style.color = '#000';
            document.CTForm.Result.value = result;
       	}
    } else {
        alert("Cannot evaluate expression on molecule:\n"+
              "no JavaScript to Java communication in your browser.\n");
    }
}

function setResultMessage(message) {
    document.CTForm.Result.style.color = '#000';
    document.CTForm.Result.value = message;
}

function propertyChange(prop) {
    if (prop.indexOf('mol=') !=-1) {
        evaluateChemicalTerms(document.CTForm.Expression.value);
    } 
}

msketch_name = "MSketch";
msketch_mayscript = true;
msketch_begin("../../..", 540, 480);
msketch_param("mol", "../../../mols-2d/psilocybin.csmol");
msketch_param("listenpropertychange","true");
msketch_end();
//-->
</script>
<p>
<form NAME="CTForm">
<table BORDER=0>
    <tr>
        <td><a href="../../../help/chemicalterms/ChemicalTerms.html">Chemical Terms</a> expression:</td>
        <td ALIGN="right">
            <select NAME="ExpressionSelector" onChange="setResultMessage('Calculating...')" onClick="evaluateChemicalTerms(this.value)">
                <option VALUE=""> --- Select expression --- </option>
                <option VALUE="mass()">Molecular weight</option>
                <option VALUE="atomCount()">Atom count</option>
                <option VALUE="bondCount()">Bond count</option>
                <option VALUE="rotatableBondCount()">Rotatable bond count</option>
                <option VALUE="ringCount()">Ring count</option>
                <option VALUE="pKa('acidic', '1')">Strongest acidic pKa</option>
                <option VALUE="pKa('basic', '1')">Strongest basic pKa</option>
                <option VALUE="logP()">logP</option>
                <option VALUE="topologicalPolarSurfaceArea()">Polar surface area</option>
                <option VALUE="acceptorCount()">H bond acceptor count</option>
                <option VALUE="donorCount()">H bond donor count</option>
                <option VALUE="mostStableTautomer()">Most stable tautomer</option>
                <option VALUE="tautomers()">Tautomers</option>
                <option VALUE="name()">IUPAC name</option>
                <option VALUE="molString('smiles')">SMILES</option>
                <option VALUE=
"(mass() <= 500) &&
(logP() <= 5) &&
(donorCount() <= 5) &&
(acceptorCount() <= 10)">Lipinski rule of 5</option>
                <option VALUE=
"(mass() <= 300) && 
(logP() <= 3) && 
(donorCount() <= 3) && 
(acceptorCount() <= 3) && 
(rotatableBondCount() <= 3) && 
(topologicalPolarSurfaceArea() <= 60)">Rule of 3</option>
            </select>
        </td>
    </tr>
    <tr>
        <td COLSPAN=2><textarea NAME="Expression" ROWS=5 COLS=75 onKeyDown="setResultMessage('Calculating...')" onFocus="editing=true" 
            onBlur="editing=false" onKeyUp="if (editing) { evaluateChemicalTerms(document.CTForm.Expression.value) }"></textarea></td>
    </tr>
</table>
<table>
    <tr>
        <td>Result:</td>
    </tr>
    <tr>
        <td><textarea NAME="Result" ROWS=5 COLS=75></textarea></td>
    </tr>
</table>
</form>
</center>

<p>

<!-- Code highlight BEGIN -->
<blockquote>
<pre class="sh_html">
&lt;!--  Important!  --&gt;
&lt;body onUnLoad="document.MSketch=null" &gt;
&lt;script LANGUAGE="JavaScript1.1"&gt;
&lt;!--
</pre><pre class="sh_javascript">function evaluateChemicalTerms(expression) {
    document.CTForm.Expression.value = expression;
    if(document.MSketch != null) {
        var result = document.MSketch.evaluateChemicalTerms(expression);
        if (document.MSketch.isChemicalTermsExpressionSyntaxError()) {
            document.CTForm.Result.style.color = '#F00';
       	    document.CTForm.Result.value = "Syntax error.";
        } else {
            document.CTForm.Result.style.color = '#000';
            document.CTForm.Result.value = result;
       	}
    } else {
        alert("Cannot evaluate expression on molecule:\n"+
              "no JavaScript to Java communication in your browser.\n");
    }
}

function setResultMessage(message) {
    document.CTForm.Result.style.color = '#000';
    document.CTForm.Result.value = message;
}

function propertyChange(prop) {
    if (prop.indexOf('mol=') !=-1) {
        evaluateChemicalTerms(document.CTForm.Expression.value);
    }
}

msketch_name = "MSketch";
msketch_mayscript = true;
msketch_begin("../../..", 540, 480);
msketch_param("mol", "../../../mols-2d/psilocybin.csmol");
msketch_param("listenpropertychange","true");
msketch_end();
</pre><pre class="sh_html">    
//--&gt;
&lt;/script&gt;
&lt;p&gt;
&lt;form NAME="CTForm"&gt;
&lt;table BORDER=0&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;a href="../../../help/chemicalterms/ChemicalTerms.html"&gt;Chemical Terms&lt;/a&gt; expression:&lt;/td&gt;
        &lt;td ALIGN="right"&gt;
            &lt;select NAME="ExpressionSelector" onChange="setResultMessage('Calculating...')" onClick="evaluateChemicalTerms(this.value)"&gt;
                &lt;option VALUE=""&gt; --- Select expression --- &lt;/option&gt;
                &lt;option VALUE="mass()"&gt;Molecular weight&lt;/option&gt;
                &lt;option VALUE="atomCount()"&gt;Atom count&lt;/option&gt;
                &lt;option VALUE="bondCount()"&gt;Bond count&lt;/option&gt;
                &lt;option VALUE="rotatableBondCount()"&gt;Rotatable bond count&lt;/option&gt;
                &lt;option VALUE="ringCount()"&gt;Ring count&lt;/option&gt;
                &lt;option VALUE="pKa('acidic', '1')"&gt;Strongest acidic pKa&lt;/option&gt;
                &lt;option VALUE="pKa('basic', '1')"&gt;Strongest basic pKa&lt;/option&gt;
                &lt;option VALUE="logP()"&gt;logP&lt;/option&gt;
                &lt;option VALUE="topologicalPolarSurfaceArea()"&gt;Polar surface area&lt;/option&gt;
                &lt;option VALUE="acceptorCount()"&gt;H bond acceptor count&lt;/option&gt;
                &lt;option VALUE="donorCount()"&gt;H bond donor count&lt;/option&gt;
                &lt;option VALUE="mostStableTautomer()"&gt;Most stable tautomer&lt;/option&gt;
                &lt;option VALUE="tautomers()"&gt;Tautomers&lt;/option&gt;
                &lt;option VALUE="name()"&gt;IUPAC name&lt;/option&gt;
                &lt;option VALUE="molString('smiles')"&gt;SMILES&lt;/option&gt;
                &lt;option VALUE=
                    "(mass() &lt;= 500) &&
                    (logP() &lt;= 5) &&
                    (donorCount() &lt;= 5) &&
                    (acceptorCount() &lt;= 10)"&gt;Lipinski rule of 5&lt;/option&gt;
                                    &lt;option VALUE=
                    "(mass() &lt;= 300) &&
                    (logP() &lt;= 3) &&
                    (donorCount() &lt;= 3) &&
                    (acceptorCount() &lt;= 3) &&
                    (rotatableBondCount() &lt;= 3) &&
                    (topologicalPolarSurfaceArea() &lt;= 60)"&gt;Rule of 3&lt;/option&gt;
            &lt;/select&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td COLSPAN=2&gt;&lt;textarea NAME="Expression" ROWS=5 COLS=75 onKeyDown="setResultMessage('Calculating...')" onFocus="editing=true"
            onBlur="editing=false" onKeyUp="if (editing) { evaluateChemicalTerms(document.CTForm.Expression.value) }"&gt;&lt;/textarea&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
&lt;table&gt;
    &lt;tr&gt;
        &lt;td&gt;Result:&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;textarea NAME="Result" ROWS=5 COLS=75&gt;&lt;/textarea&gt;&lt;/td&gt;
    &lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
</pre>
</blockquote>
<!-- Code highlight END -->


<p>

<center><div class="lenia">&nbsp;</div></center>
<p>In the <a HREF="chemicalterms2.html">next example</a> more than one property calculation is performed each time the molecule is altered.</p>

</body>
</html>
